﻿using MDK.Device.Components;

namespace MDK.Device.Devices
{
    public class FrontDevice
    {
        public FrontDevice(IPlcDevice device)
        {
            Device = device;
            InitializeComponents();
        }
        public IPlcDevice Device { get; }
        public ISensor[] PositionSensors { get; private set; }
        public IAxle X { get; private set; }
        public IAxle Y { get; private set; }
        public IAxle Z { get; private set; }
        public IAxle SZ { get; private set; }
        public ISwitch Finger { get; private set; }
        public ISwitch Lamp { get; private set; }
        public ISwitch UVLamp { get; private set; }
        /// <summary>
        /// 警报
        /// </summary>
        public ISwitch Alert { get; set; }
        /// <summary>
        /// 安全光栅
        /// </summary>
        public ISensor Raster { get; private set; }
        public ISwitch RasterSwitch { get; private set; }
        public IWeigher Weigher { get; private set; }
        public IScanner FingerScanner { get; private set; }
        public IScanner FreezerBeltScanner { get; private set; }
        public ISensor FingerCheckSensor { get; private set; }
        public ISensor FingerRecheckSensor { get; private set; }

        private void InitializeComponents()
        {
            PositionSensors = new ISensor[]
            {
                new Sensor(Device, "X00"), new Sensor(Device, "X01"), new Sensor(Device, "X02"), new Sensor(Device, "X03"), new Sensor(Device, "X04"), new Sensor(Device, "X05"), new Sensor(Device, "X06"), new Sensor(Device, "X07"),
                new Sensor(Device, "X10"), new Sensor(Device, "X11"), new Sensor(Device, "X12"), new Sensor(Device, "X13"), new Sensor(Device, "X14"), new Sensor(Device, "X15"), new Sensor(Device, "X16"), new Sensor(Device, "X17"),
                new Sensor(Device, "X20"), new Sensor(Device, "X21"), new Sensor(Device, "X22"), new Sensor(Device, "X23"), new Sensor(Device, "X24"), new Sensor(Device, "X25"), new Sensor(Device, "X26"), new Sensor(Device, "X27"),
                new Sensor(Device, "X30"), new Sensor(Device, "X31"), new Sensor(Device, "X32"), new Sensor(Device, "X33"), new Sensor(Device, "X34"), new Sensor(Device, "X35"), new Sensor(Device, "X36"), new Sensor(Device, "X37"),
                new Sensor(Device, "X40"), new Sensor(Device, "X41"), new Sensor(Device, "X42"), new Sensor(Device, "X43"), new Sensor(Device, "X44"), new Sensor(Device, "X45"), new Sensor(Device, "X46"), new Sensor(Device, "X47"),
            };

            X = new StdAxle(Device, "DD34", "DD100", "L0", "M30", "M358", "M20", "M21", "DD36", "M350", "M356", "D7", "X61", "X60", "X62","M359");
            Y = new StdAxle(Device, "DD38", "DD102", "L1", "M32", "M362", "M22", "M23", "DD40", "M352", "M360", "D10", "X64", "X63", "X65","M363") ;
            Z = new StdAxle(Device, "DD42", "DD104", "L2", "M34", "M366", "M24", "M25", "DD44", "M354", "M364", "D13", "X67", "X70", "X66","M367");
            SZ = new LocationAxle(Device, new PlcAddress[]{ "M26", "M27", "M28", "M37" }, "D18", "M36", "M29", "X55", "X52");
            Finger = new DoubleBitSwitch(Device, "M69", "M70");
            Lamp = new Switch(Device, "M175");
            UVLamp = new Switch(Device, "M174");
            Raster = new Sensor(Device, "M40");
            RasterSwitch = new Switch(Device, "M39");
            FingerCheckSensor = new Sensor(Device, "X104");
            FingerRecheckSensor = new Sensor(Device, "X105");
            Alert = new Switch(Device, "M38");
            FingerScanner = new SerialPortScanner(Device, "M120", 13, "COM2", "COM3", "COM4");
        }
    }
}